/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package construtora.limiar.dao.generic;

import construtora.limiar.dao.generic.DAOEngine;
import construtora.limiar.models.generic.IModel;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


/**
 *
 * @author michel
 */
public abstract class AbstractDAO {
    
    protected String table;
        
    public String getTable() {
        return table;
    }
    
    public boolean insert(IModel model) {
        String[][] fields = this.getFields(model);
        return DAOEngine.insert(this.table, fields);
    }
    
    public boolean update(IModel model) {
        String[][] fields = this.getFields(model);
        return DAOEngine.update(this.table, fields, this.getDefaultWhere(model));
    }
    
    public boolean delete(IModel model) {
        return DAOEngine.delete(this.table, this.getDefaultWhere(model));
    }
    
    public String getDefaultWhere(IModel model){
        return model.getPrimaryKey()+" = "+model.getId();
    }
    
    public abstract String[][] getFields(IModel model);
    
    public Integer getLast(IModel model){
        return DAOEngine.lastValue(this.table, model.getPrimaryKey());  
    }






    
}
